#include "CameraObject.h"
#include "Transformation.h"
#include "Camera.h"
#include "Follower.h"
#include "Scene.h"
#include "Rect.h"

using namespace game_engine;
using namespace game_engine::library;
using namespace game_engine::components;
using namespace game_engine::utils;

///////////////////////////////////////////////////////////////////////////////
// Constructors and Destructors
///////////////////////////////////////////////////////////////////////////////

CameraObject::CameraObject(void)
    : GameObject()
{
}

CameraObject::CameraObject(Scene *scn, const string &n, const string &t, 
    const DrawLevelType d)
    : GameObject(scn, n, t, d)
{
    // Create its components
    Transformation *camTransf = new Transformation(this, 0.0, 0.0, 
        0.0, 0.0, 1.0, 1.0);
    Camera *cam = new Camera(this, Rect());
    Follower *follow = new Follower(this);

    // Add components to object
    addComponent(camTransf);
    addComponent(cam);
    addComponent(follow);
}

CameraObject::~CameraObject(void)
{
}

///////////////////////////////////////////////////////////////////////////////
// Setters
///////////////////////////////////////////////////////////////////////////////

void CameraObject::setInitialPosition(const Point &iniPos)
{
    // Get the Transformation component
    Transformation *transf = 
        dynamic_cast<Transformation*> (getComponent("Transformation"));
    transf->setPosition(iniPos);

    // Get the Follower component
    Follower *follower = dynamic_cast<Follower*> (getComponent("Follower"));
    follower->setInitialPosition(iniPos);
}

void CameraObject::setView(const Rect &view)
{
    // Get the Camera component
    Camera *cam = dynamic_cast<Camera*> (getComponent("Camera"));
    cam->setView(view);
}

void CameraObject::setFollowed(GameObject *obj)
{
    // Get the Follower component
    Follower *follower = dynamic_cast<Follower*> (getComponent("Follower"));
    follower->setSubject(obj);
}
